USE ConsultTracking
GO

drop proc CreateCustomer
drop proc UpdateCustomer
drop proc GetCustomerData
GO
------------------------------------------------------------------
create proc CreateCustomer
@CustomerName nvarchar(100),
@Phone nvarchar(100) = '',
@Fax nvarchar(100) = '',
@CustomerID int output,
@Active bit output,
@Created smalldatetime output,
@Modified smalldatetime output
as
INSERT INTO [ConsultTracking].[dbo].[Customer]
           ([CustomerName]
           ,[Phone]
           ,[Fax])
     VALUES
           (@CustomerName
           ,@Phone
           ,@Fax);

SELECT @CustomerID = [CustomerID]
      ,@Active = [Active]
      ,@Created = [Created]
      ,@Modified = [Modified]
  FROM [ConsultTracking].[dbo].[Customer]
	WHERE CustomerID = SCOPE_IDENTITY()
-------------------------------------------------------------------
go
create proc UpdateCustomer
@CustomerID int,
@CustomerName nvarchar(100),
@Phone nvarchar(100),
@Fax nvarchar(100),
@Active BIT,
@Modified smalldatetime 
as
UPDATE [ConsultTracking].[dbo].[Customer]
   SET [CustomerName] = @CustomerName
      ,[Phone] = @Phone
      ,[Fax] = @Fax
	  ,[Active] = @Active
	  ,[Modified] = GETDATE()
 WHERE CustomerID = @CustomerID and Modified = @Modified;


SELECT @Modified = [Modified]
  FROM [ConsultTracking].[dbo].[Customer]
	WHERE CustomerID = @CustomerID

------------------------------------------------------------------
go
create proc GetCustomerData
as
SELECT * FROM Customer